/*     */ package com.newcrm.db;
/*     */ 
/*     */ import com.alibaba.druid.pool.DruidDataSource;
/*     */ import com.newcrm.config.Config;
/*     */ import com.newcrm.config.MyDBSetting;
/*     */ import java.sql.Connection;
/*     */ import java.sql.SQLException;
/*     */ import org.apache.log4j.Logger;
/*     */ 
/*     */ public class ConnectionManager
/*     */ {
/*  14 */   private static Logger logger = Logger.getLogger(ConnectionManager.class
/*  15 */     .getName());
/*     */ 
/*  17 */   private static ConnectionManager instance = new ConnectionManager();
/*     */ 
/*  22 */   private DruidDataSource dataSource = null;
/*     */ 
/*     */   private ConnectionManager()
/*     */   {
/*  29 */     Config config = Config.getInstance();
/*  30 */     MyDBSetting myDBSetting = MyDBSetting.getInstance();
/*     */     try
/*     */     {
/*  58 */       this.dataSource = new DruidDataSource();
/*     */ 
/*  60 */       if ((myDBSetting.dbJdbcUrl != null) && 
/*  61 */         (myDBSetting.dbJdbcUrl.length() > 0)) {
/*  62 */         this.dataSource.setUsername(myDBSetting.user);
/*  63 */         this.dataSource.setPassword(myDBSetting.pwd);
/*  64 */         this.dataSource.setUrl(myDBSetting.dbJdbcUrl);
/*     */       } else {
/*  66 */         this.dataSource.setUsername(config.user);
/*  67 */         this.dataSource.setPassword(config.pwd);
/*  68 */         this.dataSource.setUrl(config.dbJdbcUrl);
/*     */       }
/*     */ 
/*  71 */       this.dataSource.setFilters(config.filters);
/*     */ 
/*  73 */       this.dataSource.setInitialSize(config.initialSize);
/*  74 */       this.dataSource.setMinIdle(config.minIdle);
/*  75 */       this.dataSource.setMaxActive(config.maxActive);
/*     */ 
/*  77 */       this.dataSource.setMaxWait(config.maxWait);
/*     */ 
/*  79 */       this.dataSource
/*  80 */         .setTimeBetweenEvictionRunsMillis(config.timeBetweenEvictionRunsMillis);
/*  81 */       this.dataSource
/*  82 */         .setMinEvictableIdleTimeMillis(config.minEvictableIdleTimeMillis);
/*     */ 
/*  84 */       this.dataSource.setValidationQuery(config.validationQuery);
/*  85 */       this.dataSource.setTestWhileIdle(config.testWhileIdle);
/*  86 */       this.dataSource.setTestOnBorrow(config.testOnBorrow);
/*  87 */       this.dataSource.setTestOnReturn(config.testOnReturn);
/*     */ 
/*  89 */       this.dataSource
/*  90 */         .setPoolPreparedStatements(config.poolPreparedStatements);
/*  91 */       this.dataSource
/*  92 */         .setMaxOpenPreparedStatements(config.maxOpenPreparedStatements);
/*     */     }
/*     */     catch (Exception e) {
/*  95 */       logger.warn("create data source failed", e);
/*     */     }
/*     */   }
/*     */ 
/*     */   public static ConnectionManager getInstance()
/*     */   {
/* 105 */     return instance;
/*     */   }
/*     */ 
/*     */   public static synchronized void reConnect()
/*     */   {
/* 112 */     if (instance != null) {
/* 113 */       Connection conn = instance.getConnection();
/* 114 */       if (conn != null) {
/*     */         try {
/* 116 */           conn.close();
/*     */         } catch (SQLException e) {
/* 118 */           logger.warn("close connection failed", e);
/*     */         }
/*     */       }
/*     */     }
/* 122 */     instance = new ConnectionManager();
/*     */   }
/*     */ 
/*     */   public final synchronized Connection getConnection()
/*     */   {
/* 131 */     Connection conn = null;
/*     */     try {
/* 133 */       conn = this.dataSource.getConnection();
/*     */     } catch (SQLException e) {
/* 135 */       logger.warn("get connection failed", e);
/*     */     }
/* 137 */     return conn;
/*     */   }
/*     */ }

/* Location:           C:\E\referenceProject\CRM参考\qikebao\WEB-INF\lib\qikebao.jar
 * Qualified Name:     com.newcrm.db.ConnectionManager
 * JD-Core Version:    0.6.1
 */